package pl.wroc.uni.ii.evolution.distribution.workers.standalone;
import pl.wroc.uni.ii.evolution.distribution.workers.EvTaskLoaderImpl;
import pl.wroc.uni.ii.evolution.distribution.workers.EvTaskMaster;
import pl.wroc.uni.ii.evolution.distribution.workers.EvJARCacheImpl;
import pl.wroc.uni.ii.evolution.servlets.managment.communication.EvManagmentServletCommunication;
import pl.wroc.uni.ii.evolution.servlets.managment.communication.EvManagmentServletCommunicationImpl;

public class EvConsoleWorker {

  /**
   * @param args
   */
  public static void main(String[] args) {
    
    String tomcat_url = "";
    
    try {
      tomcat_url = args[0];
    } catch (Exception ex) {
      System.out.println("Usage: java -jar wevo_client.jar <tomcat_url>");
      return;
    }
    
    String managment_servlet_url = tomcat_url + "/wevo_system/DistributionManager";
    String download_servlet_url = tomcat_url + "/wevo_databasesupport/DownloadServlet";
    String upload_servlet_url = tomcat_url + "/wevo_databasesupport/UploadServlet";
    
    /** create object used for communication with servlets */
    EvManagmentServletCommunication proxy = new EvManagmentServletCommunicationImpl(managment_servlet_url);
    EvTaskLoaderImpl loader = new EvTaskLoaderImpl(download_servlet_url, upload_servlet_url, managment_servlet_url);
  
    EvJARCacheImpl jar_manager = new EvJARCacheImpl(proxy);
    jar_manager.init();
    
    EvTaskMaster interaction = new EvTaskMaster(proxy, loader, jar_manager, 2000);

    /** start interaction with managment servlet */
    interaction.run();
    
  }
}